package com.andreas.message;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

import static com.andreas.utils.ConnectionUtils.getConnection;

/**
 * 描述：消息发送者 工作队列模式
 */
public class MessageSender {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = getConnection();
        Channel channel = connection.createChannel();
        // 声明队列（此处为生产者，创建队列）注明出餐口位置，通知大家来排队
        channel.queueDeclare("test_work_queue", false, false, false, null);
        for (int i = 0; i < 100; i++) {
            String msg = "羊肉串 --> " + (i + 1);
            channel.basicPublish("", "test_work_queue", null, msg.getBytes(StandardCharsets.UTF_8));
            System.out.println("师傅烤好：" + msg);
        }
        channel.close();
        connection.close();
    }
}
